/**** Deletion of Database Specific Datatypes begins ****/
IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'AccountNumberField')
EXECUTE sp_droptype N'AccountNumberField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'ActionField')
EXECUTE sp_droptype N'ActionField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'AddressLineField')
EXECUTE sp_droptype N'AddressLineField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'AmountField') 
EXECUTE sp_droptype N'AmountField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'AuthCodeField')
EXECUTE sp_droptype N'AuthCodeField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'BigConfigDataField')
EXECUTE sp_droptype N'BigConfigDataField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'BigDataField')
EXECUTE sp_droptype N'BigDataField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'MediumTextField')
EXECUTE sp_droptype N'MediumTextField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'BigTextField')
EXECUTE sp_droptype N'BigTextField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'BitmapHexField')
EXECUTE sp_droptype N'BitmapHexField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'BooleanField')
EXECUTE sp_droptype N'BooleanField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'CardPANField')
EXECUTE sp_droptype N'CardPANField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'DescriptionField')
EXECUTE sp_droptype N'DescriptionField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'DateTimeField')
EXECUTE sp_droptype N'DateTimeField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'DoubleField')
EXECUTE sp_droptype N'DoubleField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'IdentifierField')
EXECUTE sp_droptype N'IdentifierField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'ImageField')
EXECUTE sp_droptype N'ImageField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'IntField')
EXECUTE sp_droptype N'IntField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'KeyOrIDField')
EXECUTE sp_droptype N'KeyOrIDField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'NameField')
EXECUTE sp_droptype N'NameField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'PasswordField')
EXECUTE sp_droptype N'PasswordField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'MasterSmallIDField')
EXECUTE sp_droptype N'MasterSmallIDField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'NullableKeyorIDField')
EXECUTE sp_droptype N'NullableKeyorIDField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'PhoneNumberField')
EXECUTE sp_droptype N'PhoneNumberField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'PinField')
EXECUTE sp_droptype N'PinField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'PercentageField')
EXECUTE sp_droptype N'PercentageField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'RateField')
EXECUTE sp_droptype N'RateField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'RFUField')
EXECUTE sp_droptype N'RFUField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'StatusField')
EXECUTE sp_droptype N'StatusField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'SmallConfigDataField')
EXECUTE sp_droptype N'SmallConfigDataField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'SmallIdentifierField')
EXECUTE sp_droptype N'SmallIdentifierField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'TinyIntField')
EXECUTE sp_droptype N'TinyIntField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'UserNameField')
EXECUTE sp_droptype N'UserNameField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'SmallStatusOrReasonField')
EXECUTE sp_droptype N'SmallStatusOrReasonField'
GO

IF EXISTS (SELECT * FROM [dbo].[systypes] WHERE NAME = N'SmallCountField')
EXECUTE sp_droptype N'SmallCountField'
GO
/**** Deletion of Database Specific Datatypes ends ****/

/**** Creation of Database Specific Datatypes begins ****/
SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'AccountNumberField', N'VARCHAR(14)', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'ActionField', N'VARCHAR(20)', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'AddressLineField', N'VARCHAR(100)', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'AmountField', N'NUMERIC(10,0)', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'CoordinateField', N'NUMERIC(13,10)', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'AuthCodeField', N'NUMERIC(16)', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'BigConfigDataField', N'TEXT', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'BigDataField', N'VARCHAR(4000)', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'BigTextField', N'VARCHAR(500)', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'MediumTextField', N'VARCHAR(2000)', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'BitmapHexField', N'VARBINARY(7000)', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'BooleanField', N'BIT', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'CardPANField', N'NUMERIC(20,0)', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'DescriptionField', N'VARCHAR(150)', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'DoubleField', N'NUMERIC(10,2)', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'IdentifierField', N'VARCHAR(100)', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'ImageField', N'IMAGE', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'IntField', N'INT', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'KeyOrIDField', N'NUMERIC(10,0)', N'NOT NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'NameField', N'VARCHAR(50)', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'PasswordField', N'VARCHAR(50)', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'PercentageField', N'NUMERIC(3,2)', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'DateTimeField', N'DATETIME', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'MasterSmallIDField', N'NUMERIC(4,0)', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'NullableKeyorIDField', N'NUMERIC(10,0)', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'PhoneNumberField', N'VARCHAR(14)', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'PinField', N'NUMERIC(6,0)', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'RateField', N'NUMERIC(6,0)', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'RFUField', N'VARCHAR(50)', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'StatusField', N'TINYINT', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'SmallConfigDataField', N'VARCHAR(50)', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'SmallIdentifierField', N'VARCHAR(20)', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'TinyIntField', N'TINYINT', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'UserNameField', N'VARCHAR(50)', N'NULL'
GO
SETUSER
GO
/**** Creation of Database Specific Datatypes ends ****/

/**** Deletion of Database Specific Foreign Key Constraints begins ****/
IF EXISTS (SELECT * FROM [dbo].[sysobjects] WHERE id = OBJECT_ID(N'[dbo].[FK_SCHD_JOB_ASSOCIATIONS_SCHD_JOB_DETAILS]') AND OBJECTPROPERTY(id, N'IsConstraint') = 1)
ALTER TABLE [dbo].[SCHD_JOB_ASSOCIATIONS]
DROP CONSTRAINT FK_SCHD_JOB_ASSOCIATIONS_SCHD_JOB_DETAILS
GO

IF EXISTS (SELECT * FROM [dbo].[sysobjects] WHERE id = OBJECT_ID(N'[dbo].[FK_SCHD_JOB_ASSOCIATIONS_SCHD_CRON_TRIGGERS]') AND OBJECTPROPERTY(id, N'IsConstraint') = 1)
ALTER TABLE [dbo].[SCHD_JOB_ASSOCIATIONS]
DROP CONSTRAINT FK_SCHD_JOB_ASSOCIATIONS_SCHD_CRON_TRIGGERS
GO
/**** Deletion of Database Specific Foreign Key Constraints ends ****/


IF EXISTS (SELECT * FROM [dbo].[sysobjects] WHERE id = OBJECT_ID(N'[dbo].[Image_Type]') 
AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[Image_Type]
GO

IF EXISTS (SELECT * FROM [dbo].[sysobjects] WHERE id = OBJECT_ID(N'[dbo].[QRTZ_BLOB_TRIGGERS]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[QRTZ_BLOB_TRIGGERS]
GO

IF EXISTS (SELECT * FROM [dbo].[sysobjects] WHERE id = OBJECT_ID(N'[dbo].[QRTZ_CALENDARS]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[QRTZ_CALENDARS]
GO

IF EXISTS (SELECT * FROM [dbo].[sysobjects] WHERE id = OBJECT_ID(N'[dbo].[QRTZ_CRON_TRIGGERS]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[QRTZ_CRON_TRIGGERS]
GO

IF EXISTS (SELECT * FROM [dbo].[sysobjects] WHERE id = OBJECT_ID(N'[dbo].[QRTZ_FIRED_TRIGGERS]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[QRTZ_FIRED_TRIGGERS]
GO

IF EXISTS (SELECT * FROM [dbo].[sysobjects] WHERE id = OBJECT_ID(N'[dbo].[QRTZ_JOB_DETAILS]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[QRTZ_JOB_DETAILS]
GO

IF EXISTS (SELECT * FROM [dbo].[sysobjects] WHERE id = OBJECT_ID(N'[dbo].[QRTZ_JOB_LISTENERS]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[QRTZ_JOB_LISTENERS]
GO

IF EXISTS (SELECT * FROM [dbo].[sysobjects] WHERE id = OBJECT_ID(N'[dbo].[QRTZ_LOCKS]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[QRTZ_LOCKS]
GO

IF EXISTS (SELECT * FROM [dbo].[sysobjects] WHERE id = OBJECT_ID(N'[dbo].[QRTZ_PAUSED_TRIGGER_GRPS]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[QRTZ_PAUSED_TRIGGER_GRPS]
GO

IF EXISTS (SELECT * FROM [dbo].[sysobjects] WHERE id = OBJECT_ID(N'[dbo].[QRTZ_SCHEDULER_STATE]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[QRTZ_SCHEDULER_STATE]
GO

IF EXISTS (SELECT * FROM [dbo].[sysobjects] WHERE id = OBJECT_ID(N'[dbo].[QRTZ_SIMPLE_TRIGGERS]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[QRTZ_SIMPLE_TRIGGERS]
GO

IF EXISTS (SELECT * FROM [dbo].[sysobjects] WHERE id = OBJECT_ID(N'[dbo].[QRTZ_TRIGGER_LISTENERS]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[QRTZ_TRIGGER_LISTENERS]
GO

IF EXISTS (SELECT * FROM [dbo].[sysobjects] WHERE id = OBJECT_ID(N'[dbo].[QRTZ_TRIGGERS]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[QRTZ_TRIGGERS]
GO

IF EXISTS (SELECT * FROM [dbo].[sysobjects] WHERE id = OBJECT_ID(N'[dbo].[SCHD_CRON_TRIGGERS]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[SCHD_CRON_TRIGGERS]
GO

IF EXISTS (SELECT * FROM [dbo].[sysobjects] WHERE id = OBJECT_ID(N'[dbo].[SCHD_JOB_ASSOCIATIONS]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[SCHD_JOB_ASSOCIATIONS]
GO

IF EXISTS (SELECT * FROM [dbo].[sysobjects] WHERE id = OBJECT_ID(N'[dbo].[SCHD_JOB_DETAILS]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[SCHD_JOB_DETAILS]
GO

IF EXISTS (SELECT * FROM [dbo].[sysobjects] WHERE id = OBJECT_ID(N'[dbo].[SCHD_JOB_HISTORY]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
DROP TABLE [dbo].[SCHD_JOB_HISTORY]
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'SmallStatusOrReasonField', N'VARCHAR(5)', N'NULL'
GO
SETUSER
GO

SET NOCOUNT ON
SETUSER
GO
EXECUTE sp_addtype N'SmallCountField', N'NUMERIC(2,0)', N'NULL'
GO
SETUSER
GO

/**** Deletion of common utility tables ends ****/
/**** Creation of common utility tables begins ****/
CREATE TABLE [dbo].[Image_Type](
	[Image_TypeID] [KeyOrIDField] IDENTITY(1,1) NOT NULL,
	[Name] [IdentifierField] NULL,
	[Description] [IdentifierField] NULL,
	[TypeID] [KeyOrIDField] NULL,
	[Original_Image] [ImageField] NULL ,
	[ThumbNail_Image] [ImageField] NULL ,
	[CreatedBy] [NameField] NULL,
	[CreatedOn] [DateTimeField] NOT NULL,
	[ModifiedBy] [NameField] NULL,
	[ModifiedOn] [DateTimeField] NULL,
	[RFU1] [IdentifierField] NULL,
	[RFU2] [IdentifierField] NULL,
	[RFU3] [IdentifierField] NULL
) ON [PRIMARY]
GO

IF OBJECT_ID(N'[dbo].[Image_Type]') IS NOT NULL
	PRINT '<<< CREATED TABLE [Image_Type] >>>'
ELSE
	PRINT '<<< FAILED CREATING TABLE [Image_Type] >>>'
GO

CREATE TABLE [dbo].[QRTZ_BLOB_TRIGGERS] (
	[TRIGGER_NAME] [VARCHAR] (80)  NOT NULL ,
	[TRIGGER_GROUP] [VARCHAR] (80)  NOT NULL ,
	[BLOB_DATA] [IMAGE] NULL
) ON [PRIMARY]
GO

IF OBJECT_ID(N'[dbo].[QRTZ_BLOB_TRIGGERS]') IS NOT NULL
	PRINT '<<< CREATED TABLE [QRTZ_BLOB_TRIGGERS] >>>'
ELSE
	PRINT '<<< FAILED CREATING TABLE [QRTZ_BLOB_TRIGGERS] >>>'
GO

CREATE TABLE [dbo].[QRTZ_CALENDARS] (
	[CALENDAR_NAME] [VARCHAR] (80)  NOT NULL ,
	[CALENDAR] [IMAGE] NOT NULL
) ON [PRIMARY]
GO

IF OBJECT_ID(N'[dbo].[QRTZ_CALENDARS]') IS NOT NULL
	PRINT '<<< CREATED TABLE [QRTZ_CALENDARS] >>>'
ELSE
	PRINT '<<< FAILED CREATING TABLE [QRTZ_CALENDARS] >>>'
GO

CREATE TABLE [dbo].[QRTZ_CRON_TRIGGERS] (
	[TRIGGER_NAME] [VARCHAR] (80)  NOT NULL ,
	[TRIGGER_GROUP] [VARCHAR] (80)  NOT NULL ,
	[CRON_EXPRESSION] [VARCHAR] (80)  NOT NULL ,
	[TIME_ZONE_ID] [VARCHAR] (80) 
) ON [PRIMARY]
GO

IF OBJECT_ID(N'[dbo].[QRTZ_CRON_TRIGGERS]') IS NOT NULL
	PRINT '<<< CREATED TABLE [QRTZ_CRON_TRIGGERS] >>>'
ELSE
	PRINT '<<< FAILED CREATING TABLE [QRTZ_CRON_TRIGGERS] >>>'
GO

CREATE TABLE [dbo].[QRTZ_FIRED_TRIGGERS] (
	[ENTRY_ID] [VARCHAR] (95)  NOT NULL ,
	[TRIGGER_NAME] [VARCHAR] (80)  NOT NULL ,
	[TRIGGER_GROUP] [VARCHAR] (80)  NOT NULL ,
	[IS_VOLATILE] [VARCHAR] (1)  NOT NULL ,
	[INSTANCE_NAME] [VARCHAR] (80)  NOT NULL ,
	[FIRED_TIME] [BIGINT] NOT NULL ,
	[STATE] [VARCHAR] (16)  NOT NULL,
	[JOB_NAME] [VARCHAR] (80)  NULL ,
	[JOB_GROUP] [VARCHAR] (80)  NULL ,
	[IS_STATEFUL] [VARCHAR] (1)  NULL ,
	[REQUESTS_RECOVERY] [VARCHAR] (1)  NULL 
) ON [PRIMARY]
GO

IF OBJECT_ID(N'[dbo].[QRTZ_FIRED_TRIGGERS]') IS NOT NULL
	PRINT '<<< CREATED TABLE [QRTZ_FIRED_TRIGGERS] >>>'
ELSE
	PRINT '<<< FAILED CREATING TABLE [QRTZ_FIRED_TRIGGERS] >>>'
GO

CREATE TABLE [dbo].[QRTZ_JOB_DETAILS] (
	[JOB_NAME] [VARCHAR] (80)  NOT NULL ,
	[JOB_GROUP] [VARCHAR] (80)  NOT NULL ,
	[DESCRIPTION] [VARCHAR] (120) NULL ,
	[JOB_CLASS_NAME] [VARCHAR] (128)  NOT NULL ,
	[IS_DURABLE] [VARCHAR] (1)  NOT NULL ,
	[IS_VOLATILE] [VARCHAR] (1)  NOT NULL ,
	[IS_STATEFUL] [VARCHAR] (1)  NOT NULL ,
	[REQUESTS_RECOVERY] [VARCHAR] (1)  NOT NULL ,
	[JOB_DATA] [IMAGE] NULL
) ON [PRIMARY]
GO

IF OBJECT_ID(N'[dbo].[QRTZ_JOB_DETAILS]') IS NOT NULL
	PRINT '<<< CREATED TABLE [QRTZ_JOB_DETAILS] >>>'
ELSE
	PRINT '<<< FAILED CREATING TABLE [QRTZ_JOB_DETAILS] >>>'
GO

CREATE TABLE [dbo].[QRTZ_JOB_LISTENERS] (
	[JOB_NAME] [VARCHAR] (80)  NOT NULL ,
	[JOB_GROUP] [VARCHAR] (80)  NOT NULL ,
	[JOB_LISTENER] [VARCHAR] (80)  NOT NULL
) ON [PRIMARY]
GO

IF OBJECT_ID(N'[dbo].[QRTZ_JOB_LISTENERS]') IS NOT NULL
	PRINT '<<< CREATED TABLE [QRTZ_JOB_LISTENERS] >>>'
ELSE
	PRINT '<<< FAILED CREATING TABLE [QRTZ_JOB_LISTENERS] >>>'
GO

CREATE TABLE [dbo].[QRTZ_LOCKS] (
	[LOCK_NAME] [VARCHAR] (40)  NOT NULL 
) ON [PRIMARY]
GO

IF OBJECT_ID(N'[dbo].[QRTZ_LOCKS]') IS NOT NULL
	PRINT '<<< CREATED TABLE [QRTZ_LOCKS] >>>'
ELSE
	PRINT '<<< FAILED CREATING TABLE [QRTZ_LOCKS] >>>'
GO

CREATE TABLE [dbo].[QRTZ_PAUSED_TRIGGER_GRPS] (
	[TRIGGER_GROUP] [VARCHAR] (80)  NOT NULL 
) ON [PRIMARY]
GO

IF OBJECT_ID(N'[dbo].[QRTZ_PAUSED_TRIGGER_GRPS]') IS NOT NULL
	PRINT '<<< CREATED TABLE [QRTZ_PAUSED_TRIGGER_GRPS] >>>'
ELSE
	PRINT '<<< FAILED CREATING TABLE [QRTZ_PAUSED_TRIGGER_GRPS] >>>'
GO

CREATE TABLE [dbo].[QRTZ_SCHEDULER_STATE] (
	[INSTANCE_NAME] [VARCHAR] (80)  NOT NULL ,
	[LAST_CHECKIN_TIME] [BIGINT] NOT NULL ,
	[CHECKIN_INTERVAL] [BIGINT] NOT NULL ,
	[RECOVERER] [VARCHAR] (80)  NULL 
) ON [PRIMARY]
GO

IF OBJECT_ID(N'[dbo].[QRTZ_SCHEDULER_STATE]') IS NOT NULL
	PRINT '<<< CREATED TABLE [QRTZ_SCHEDULER_STATE] >>>'
ELSE
	PRINT '<<< FAILED CREATING TABLE [QRTZ_SCHEDULER_STATE] >>>'
GO

CREATE TABLE [dbo].[QRTZ_SIMPLE_TRIGGERS] (
	[TRIGGER_NAME] [VARCHAR] (80)  NOT NULL ,
	[TRIGGER_GROUP] [VARCHAR] (80)  NOT NULL ,
	[REPEAT_COUNT] [BIGINT] NOT NULL ,
	[REPEAT_INTERVAL] [BIGINT] NOT NULL ,
	[TIMES_TRIGGERED] [BIGINT] NOT NULL
) ON [PRIMARY]
GO

IF OBJECT_ID(N'[dbo].[QRTZ_SIMPLE_TRIGGERS]') IS NOT NULL
	PRINT '<<< CREATED TABLE [QRTZ_SIMPLE_TRIGGERS] >>>'
ELSE
	PRINT '<<< FAILED CREATING TABLE [QRTZ_SIMPLE_TRIGGERS] >>>'
GO

CREATE TABLE [dbo].[QRTZ_TRIGGER_LISTENERS] (
	[TRIGGER_NAME] [VARCHAR] (80)  NOT NULL ,
	[TRIGGER_GROUP] [VARCHAR] (80)  NOT NULL ,
	[TRIGGER_LISTENER] [VARCHAR] (80)  NOT NULL
) ON [PRIMARY]
GO

IF OBJECT_ID(N'[dbo].[QRTZ_TRIGGER_LISTENERS]') IS NOT NULL
	PRINT '<<< CREATED TABLE [QRTZ_TRIGGER_LISTENERS] >>>'
ELSE
	PRINT '<<< FAILED CREATING TABLE [QRTZ_TRIGGER_LISTENERS] >>>'
GO

CREATE TABLE [dbo].[QRTZ_TRIGGERS] (
	[TRIGGER_NAME] [VARCHAR] (80)  NOT NULL ,
	[TRIGGER_GROUP] [VARCHAR] (80)  NOT NULL ,
	[JOB_NAME] [VARCHAR] (80)  NOT NULL ,
	[JOB_GROUP] [VARCHAR] (80)  NOT NULL ,
	[IS_VOLATILE] [VARCHAR] (1)  NOT NULL ,
	[DESCRIPTION] [VARCHAR] (120) NULL ,
	[NEXT_FIRE_TIME] [BIGINT] NULL ,
	[PREV_FIRE_TIME] [BIGINT] NULL ,
	[TRIGGER_STATE] [VARCHAR] (16)  NOT NULL ,
	[TRIGGER_TYPE] [VARCHAR] (8)  NOT NULL ,
	[START_TIME] [BIGINT] NOT NULL ,
	[END_TIME] [BIGINT] NULL ,
	[CALENDAR_NAME] [VARCHAR] (80)  NULL ,
	[MISFIRE_INSTR] [SMALLINT] NULL
) ON [PRIMARY]
GO

IF OBJECT_ID(N'[dbo].[QRTZ_TRIGGERS]') IS NOT NULL
	PRINT '<<< CREATED TABLE [QRTZ_TRIGGERS] >>>'
ELSE
	PRINT '<<< FAILED CREATING TABLE [QRTZ_TRIGGERS] >>>'
GO

CREATE TABLE [dbo].[SCHD_CRON_TRIGGERS] (
	[Cron_Trigger_ID] [KeyOrIDField] IDENTITY (-1,1) NOT NULL,
	[Trigger_Name] [VARCHAR] (80)  NOT NULL ,
	[Trigger_Group] [VARCHAR] (80)  NOT NULL ,
	[Cron_Expression] [VARCHAR] (80)  NOT NULL ,
	[Time_Zone_ID] [VARCHAR] (80) 
) ON [PRIMARY]
GO

IF OBJECT_ID(N'[dbo].[SCHD_CRON_TRIGGERS]') IS NOT NULL
	PRINT '<<< CREATED TABLE [SCHD_CRON_TRIGGERS] >>>'
ELSE
	PRINT '<<< FAILED CREATING TABLE [SCHD_CRON_TRIGGERS] >>>'
GO

CREATE TABLE [dbo].[SCHD_JOB_ASSOCIATIONS] (
	[Job_Association_ID] [KeyOrIDField] IDENTITY(1,1) NOT NULL,
	[Description] [DescriptionField] NULL, 
	[Job_Detail_ID] [KeyOrIDField] NOT NULL,
	[Cron_Trigger_ID] [KeyOrIDField] NOT NULL,
	[Is_Active] [BooleanField] NOT NULL DEFAULT 1,
	[Parameters] [BigDataField] NULL
) ON [PRIMARY]
GO

IF OBJECT_ID(N'[dbo].[SCHD_JOB_ASSOCIATIONS]') IS NOT NULL
	PRINT '<<< CREATED TABLE [SCHD_JOB_ASSOCIATIONS] >>>'
ELSE
	PRINT '<<< FAILED CREATING TABLE [SCHD_JOB_ASSOCIATIONS] >>>'
GO

CREATE TABLE [dbo].[SCHD_JOB_DETAILS] (
	[Job_Detail_ID] [KeyOrIDField] IDENTITY(1,1) NOT NULL,
	[Job_Name] [VARCHAR] (80)  NOT NULL ,
	[Job_Group] [VARCHAR] (80)  NOT NULL ,
	[Description] [DescriptionField] NULL, 
	[Job_Class_Name] [VARCHAR] (128)  NOT NULL ,
	[Is_Durable] [BooleanField] NOT NULL DEFAULT 1, 
	[Is_Volatile] [BooleanField] NOT NULL DEFAULT 0, 
	[Is_Stateful] [BooleanField] NOT NULL DEFAULT 0, 
	[Requests_Recovery] [BooleanField] NOT NULL DEFAULT 0, 
	[Job_Data] [IMAGE] NULL 
) ON [PRIMARY]
GO

IF OBJECT_ID(N'[dbo].[SCHD_JOB_DETAILS]') IS NOT NULL
	PRINT '<<< CREATED TABLE [SCHD_JOB_DETAILS] >>>'
ELSE
	PRINT '<<< FAILED CREATING TABLE [SCHD_JOB_DETAILS] >>>'
GO

CREATE TABLE [dbo].[SCHD_JOB_HISTORY] (
	[Job_Name] [VARCHAR] (80)  NULL ,
	[Job_Group] [VARCHAR] (80)  NULL ,
	[Insert_Time] [BIGINT] NULL,
	[Trigger_Name] [VARCHAR] (80)  NULL ,
	[Trigger_Group] [VARCHAR] (80)  NULL ,
	[Fire_Time] [BIGINT]  NULL,
	[Next_Fire_Time] [BIGINT]  NULL,
	[Refire_Count] [INT]  NULL,
	[Result] [VARCHAR] (4000)  NULL
) ON [PRIMARY]
GO

IF OBJECT_ID(N'[dbo].[SCHD_JOB_HISTORY]') IS NOT NULL
	PRINT '<<< CREATED TABLE [SCHD_JOB_HISTORY] >>>'
ELSE
	PRINT '<<< FAILED CREATING TABLE [SCHD_JOB_HISTORY] >>>'
GO
/**** Creation of common utility tables ends ****/
/**** Creation of primary keys begins ****/
ALTER TABLE [dbo].[Image_Type] WITH NOCHECK 
ADD CONSTRAINT [PK_Image_Type] PRIMARY KEY CLUSTERED  (
	[Image_TypeID] ASC
) ON [PRIMARY] 
GO

ALTER TABLE [dbo].[QRTZ_CALENDARS] WITH NOCHECK 
ADD CONSTRAINT [PK_QRTZ_CALENDARS] PRIMARY KEY CLUSTERED (
	[CALENDAR_NAME]
) ON [PRIMARY] 
GO

ALTER TABLE [dbo].[QRTZ_CRON_TRIGGERS] WITH NOCHECK 
ADD CONSTRAINT [PK_QRTZ_CRON_TRIGGERS] PRIMARY KEY CLUSTERED
(
	[TRIGGER_NAME],
	[TRIGGER_GROUP]
) ON [PRIMARY] 
GO

ALTER TABLE [dbo].[QRTZ_FIRED_TRIGGERS] WITH NOCHECK 
ADD CONSTRAINT [PK_QRTZ_FIRED_TRIGGERS] PRIMARY KEY CLUSTERED (
	[ENTRY_ID]
) ON [PRIMARY] 
GO

ALTER TABLE [dbo].[QRTZ_PAUSED_TRIGGER_GRPS] WITH NOCHECK 
ADD CONSTRAINT [PK_QRTZ_PAUSED_TRIGGER_GRPS] PRIMARY KEY CLUSTERED (
	[TRIGGER_GROUP]
) ON [PRIMARY] 
GO

ALTER TABLE [dbo].[QRTZ_SCHEDULER_STATE] WITH NOCHECK 
ADD CONSTRAINT [PK_QRTZ_SCHEDULER_STATE] PRIMARY KEY CLUSTERED (
	[INSTANCE_NAME]
) ON [PRIMARY] 
GO

ALTER TABLE [dbo].[QRTZ_LOCKS] WITH NOCHECK 
ADD CONSTRAINT [PK_QRTZ_LOCKS] PRIMARY KEY CLUSTERED (
	[LOCK_NAME]
) ON [PRIMARY] 
GO

ALTER TABLE [dbo].[QRTZ_JOB_DETAILS] WITH NOCHECK 
ADD CONSTRAINT [PK_QRTZ_JOB_DETAILS] PRIMARY KEY CLUSTERED (
	[JOB_NAME],
	[JOB_GROUP]
)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[QRTZ_JOB_LISTENERS] WITH NOCHECK 
ADD CONSTRAINT [PK_QRTZ_JOB_LISTENERS] PRIMARY KEY CLUSTERED (
	[JOB_NAME],
	[JOB_GROUP],
	[JOB_LISTENER]
)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[QRTZ_SIMPLE_TRIGGERS] WITH NOCHECK 
ADD CONSTRAINT [PK_QRTZ_SIMPLE_TRIGGERS] PRIMARY KEY CLUSTERED (
	[TRIGGER_NAME],
	[TRIGGER_GROUP]
) ON [PRIMARY] 
GO

ALTER TABLE [dbo].[QRTZ_TRIGGER_LISTENERS] WITH NOCHECK 
ADD CONSTRAINT [PK_QRTZ_TRIGGER_LISTENERS] PRIMARY KEY CLUSTERED (
	[TRIGGER_NAME],
	[TRIGGER_GROUP],
	[TRIGGER_LISTENER]
) ON [PRIMARY] 
GO

ALTER TABLE [dbo].[QRTZ_TRIGGERS] WITH NOCHECK 
ADD CONSTRAINT [PK_QRTZ_TRIGGERS] PRIMARY KEY CLUSTERED (
	[TRIGGER_NAME],
	[TRIGGER_GROUP]
) ON [PRIMARY] 
GO

ALTER TABLE [dbo].[SCHD_CRON_TRIGGERS] WITH NOCHECK 
ADD CONSTRAINT [PK_SCHD_CRON_TRIGGERS] PRIMARY KEY CLUSTERED (
	[Cron_Trigger_ID]
) ON [PRIMARY] 
GO

ALTER TABLE [dbo].[SCHD_CRON_TRIGGERS] WITH NOCHECK 
ADD CONSTRAINT [UK_SCHD_CRON_TRIGGERS] UNIQUE (
	[Trigger_Name],
	[Trigger_Group]
) ON [PRIMARY] 
GO

ALTER TABLE [dbo].[SCHD_JOB_DETAILS] WITH NOCHECK 
ADD CONSTRAINT [PK_SCHD_JOB_DETAILS] PRIMARY KEY CLUSTERED (
	[Job_Detail_ID]
) ON [PRIMARY] 
GO

ALTER TABLE [dbo].[SCHD_JOB_DETAILS] WITH NOCHECK 
ADD CONSTRAINT [UK_SCHD_JOB_DETAILS] UNIQUE (
	[Job_Name],
	[Job_Group]
) ON [PRIMARY] 
GO

ALTER TABLE [dbo].[SCHD_JOB_ASSOCIATIONS] WITH NOCHECK 
ADD CONSTRAINT [PK_SCHD_JOB_ASSOCIATIONS] PRIMARY KEY CLUSTERED (
	[Job_Association_ID]
) ON [PRIMARY] 
GO
/**** Creation of primary keys ends ****/

/**** Creation of Database Specific Foreign Key Constraints begins ****/
ALTER TABLE [dbo].[SCHD_JOB_ASSOCIATIONS] WITH NOCHECK 
ADD CONSTRAINT [FK_SCHD_JOB_ASSOCIATIONS_SCHD_JOB_DETAILS] FOREIGN KEY (
	[Job_Detail_ID]
) REFERENCES [dbo].[SCHD_JOB_DETAILS] (
	[Job_Detail_ID]
)
GO

ALTER TABLE [dbo].[SCHD_JOB_ASSOCIATIONS] WITH NOCHECK 
ADD CONSTRAINT [FK_SCHD_JOB_ASSOCIATIONS_SCHD_CRON_TRIGGERS] FOREIGN KEY (
	[Cron_Trigger_ID]
) REFERENCES [dbo].[SCHD_CRON_TRIGGERS] (
	[Cron_Trigger_ID]
)
GO
/**** Creation of Database Specific Foreign Key Constraints ends ****/